<?php
namespace app\index\controller;
use app\model\Category as CategoryModel;
use think\Db;


class Category extends Base
{
    public function __construct(){
        $model = new CategoryModel();
        $this->model = $model;
        parent::__construct();
        
        $page_info = $this->page_info;
        $page_info['title'] = '分类';

        $this->assign([
            'model'=>$this->model,
            'page_info'=>$page_info
        ]);
    }

    public function index($id){
        $data = CategoryModel::where('id',$id)->find();
        if (!empty($data['redirect_cid'])) {
            return redirect(url('index',['id'=>$data['redirect_cid']]).'#'.$id);
        }
        // 特殊页面，特殊处理
        if (in_array($data['view_url'], ['activity'])) {
            // $activitys = Db::name('activity')->field('content',true)->limit(4)->select();
            // $this->assign([
            //     'activitys'=>$activitys
            // ]);
            return redirect('index/activity');
        }
        if (!empty($data['view_url'])) {
            $view = $data['view_url'];
        }elseif ($data['type'] == 1) {
            $view = 'detail';
        }else{
            $view = 'index';
        }
        return view($view, [
            'data'=>$data
        ]);
    }


}
